<?php

/**
 * StockArticle filter form base class.
 *
 * @package    SdCommerce
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseStockArticleFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'article_id'           => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Article'), 'add_empty' => true)),
      'departement_id'       => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Departement'), 'add_empty' => true)),
      'quantite_min'         => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'quantite_max'         => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'quantite_reservee'    => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'stock_reel'           => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'stock_theorique'      => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'casse'                => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'perte'                => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'gratuit'              => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'gain'                 => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'created_at'           => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'updated_at'           => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'm_bon_sortie_list'    => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'BonSortie')),
      'm_bon_entre_list'     => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'BonEntre')),
      'm_bon_transfert_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'BonTransfert')),
      'bon_sorties_list'     => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'BonSortie')),
    ));

    $this->setValidators(array(
      'article_id'           => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Article'), 'column' => 'id')),
      'departement_id'       => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Departement'), 'column' => 'id')),
      'quantite_min'         => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'quantite_max'         => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'quantite_reservee'    => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'stock_reel'           => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'stock_theorique'      => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'casse'                => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'perte'                => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'gratuit'              => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'gain'                 => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'created_at'           => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'updated_at'           => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'm_bon_sortie_list'    => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'BonSortie', 'required' => false)),
      'm_bon_entre_list'     => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'BonEntre', 'required' => false)),
      'm_bon_transfert_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'BonTransfert', 'required' => false)),
      'bon_sorties_list'     => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'BonSortie', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('stock_article_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addMBonSortieListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.LigneBonSortie LigneBonSortie')
      ->andWhereIn('LigneBonSortie.bon_sorite_id', $values)
    ;
  }

  public function addMBonEntreListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.LigneBonEntre LigneBonEntre')
      ->andWhereIn('LigneBonEntre.bon_entre_id', $values)
    ;
  }

  public function addMBonTransfertListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.LigneBonTransfert LigneBonTransfert')
      ->andWhereIn('LigneBonTransfert.bon_transfert_id', $values)
    ;
  }

  public function addBonSortiesListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.LigneBonSortie LigneBonSortie')
      ->andWhereIn('LigneBonSortie.bon_sortie_id', $values)
    ;
  }

  public function getModelName()
  {
    return 'StockArticle';
  }

  public function getFields()
  {
    return array(
      'id'                   => 'Number',
      'article_id'           => 'ForeignKey',
      'departement_id'       => 'ForeignKey',
      'quantite_min'         => 'Number',
      'quantite_max'         => 'Number',
      'quantite_reservee'    => 'Number',
      'stock_reel'           => 'Number',
      'stock_theorique'      => 'Number',
      'casse'                => 'Number',
      'perte'                => 'Number',
      'gratuit'              => 'Number',
      'gain'                 => 'Number',
      'created_at'           => 'Date',
      'updated_at'           => 'Date',
      'm_bon_sortie_list'    => 'ManyKey',
      'm_bon_entre_list'     => 'ManyKey',
      'm_bon_transfert_list' => 'ManyKey',
      'bon_sorties_list'     => 'ManyKey',
    );
  }
}
